package com.lianlianpay;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.lianlianpay.bean.ParameterBean;
import com.lianlianpay.bean.QuickPayMentBean;
import com.lianlianpay.constant.PaymentConstant;
import com.lianlianpay.util.SignUtil;
import com.seek.util.CommonUtil;

import net.sf.json.JSONObject;

public class LianLianQuickPayMent {
	public static QuickPayMentBean quickPayMent(Map<String,Object> map){
		QuickPayMentBean bean = new QuickPayMentBean();
		// 商户号
		bean.setOid_partner(PaymentConstant.OID_PARTNER);
		// 业务编号
		bean.setBusi_partner(PaymentConstant.LIANLIAN_BUSI_PARTNER);
		// 内部订单号
		bean.setNo_order(""+map.get("repayId"));
		// 商户订单时间
		String requestTime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
		bean.setDt_order(requestTime);
		
		//放入异步回调时，需要的参数
		bean.setInfo_order(""+map.get("repayId"));
		//支付金额：外部传入的是分，这里要转成为元
		String payMoney=new DecimalFormat("##0.00").format((double)CommonUtil.getIntValue(map.get("payMoney"))/100);
		bean.setName_goods("还款金额："+payMoney);
		bean.setMoney_order(payMoney);
		//回调url
		bean.setNotify_url(PaymentConstant.LIANLIAN_CB_URL);
		//风控参数
		ParameterBean pb= new ParameterBean();
		pb.setFrms_ware_category("2010");
		pb.setUser_info_mercht_userno(""+map.get("custId"));
		pb.setUser_info_dt_register("20170720165530");
		pb.setUser_info_bind_phone(""+map.get("phone"));
		pb.setUser_info_full_name(""+map.get("custName"));
		pb.setUser_info_id_no(""+map.get("custIdNumber"));
		pb.setUser_info_identify_state("1");
		pb.setUser_info_identify_type("1");
		JSONObject json = JSONObject.fromObject(pb);
		bean.setRisk_item(json.toString());
		
		bean.setSign_type(PaymentConstant.SIGN_TYPE);
		bean.setSign(SignUtil.genRSASign(JSON.parseObject(JSON.toJSONString(bean))));
		bean.setId_type("0");
		bean.setId_no(""+map.get("custIdNumber"));
		bean.setAcct_name(""+map.get("custName"));
		bean.setUser_id(map.get("phone")+"#"+map.get("customerId"));
		return bean;
	}

}
